package No201_300.No201_210.CountPrimes_204;

public class Solution {
	/*
	 * 给一个非负整数n，计算出比他小的素数（不包括他）
	 * 
	 * */
	public int countPrimes(int n) {
		int[] a = new int[n];
		int q = (int)Math.sqrt(n);
		for(int i = 2;i <= q; i++){
			if(a[i] == 0){
				for(int j = 2;i*j<n;j++){
					a[i*j] = 1;
				}
			}
		}
		int count = 0;
		for(int i = 2;i<n;i++){
			if(a[i] == 0){
				count++;
			}
		}
		return count;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
